<?php

namespace app\common\model\region;

use app\common\model\BaseModel;

class Region extends BaseModel
{
    protected $name = 'region';
    protected $pk = 'id';
    protected $globalScope = [];

    public function regionOptions()
    {
        $model = $this;
        $regionOptions = $model->where('is_delete', '=', '0')->select()->toArray();

        return get_tree_children($regionOptions);
    }

    public function allMergerNames()
    {
        $model = $this;
        $allItems = $model->select()->toArray();

        $allMergerNames = [];
        foreach ($allItems as $item) {
//            $allMergerNames[$item["id"]] = str_replace(",", "/", trim($item["merger_name"], "中国,"));
            $allMergerNames[$item["id"]] = str_replace(",", "/", substr($item["merger_name"], strlen("中国,")));
//            $allMergerNames[$item["id"]] = $item["merger_name"];
        }

        return $allMergerNames;
    }

    public static function getMergerName($id)
    {
        $merger_name = static::withoutGlobalScope()
            ->where("id", '=', $id)
            ->value('merger_name');
        return str_replace(",", "/", substr($merger_name??'', strlen("中国,")));
    }
    public static function getCityName($id)
    {
        $city_name = static::withoutGlobalScope()
            ->where("id", '=', $id)
            ->value('name');
        return $city_name;
    }

}